﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using XXN.Model;
using XXN.Service;

namespace XXN.Admin.Controllers
{
    public class LoginController : Controller
    {
        // GET: Login
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Login(string userName, string pwd)
        {
            UserServer Us = new UserServer();
            UserUI user = Us.GetUser(userName);
            if (user == null)
            {
                return Json(new { Success = false, Message = "用户名不存在" });
            }
            else
            {
                if (user.Password == pwd)
                {
                    FormsAuthentication.SetAuthCookie(userName, false);//颁发通行证
                    user.CreateTime = DateTime.Now;
                    //未填写
                    return Json(new { Success = true, Message = userName });
                }
                {
                    return Json(new { Success = false, Message = "密码错误" });
                }
            }
        }
        public ActionResult LoginOut()
        {
            FormsAuthentication.SignOut();
            return Redirect("/Login/Index");
        }
    }
}